<template>
  <div>
    <div class="table">
      <el-table
        :data="tableData"
        style="width: 100%"
        @sort-change="sort"
        border
        class="tableBox">
        <el-table-column
          :key="index"
          v-for="(item, index) in datalist"
          :prop="item.prop"
          :label="item.label"
          :sortable="'custom'"
          :align="item.align">
        </el-table-column>
        <el-table-column label="证明材料" align="center">
          <template slot-scope="scope">
            <el-button @click="look(scope.row)" size="mini" type="primary">预览</el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="isProved"
          label="是否认证"
          :sortable="'custom'"
          align="center">
        </el-table-column>
        <!-- 操作 -->
        <el-table-column label="操作" align="center">
          <!-- slot-scope="scope" 这里取到当前单元格 -->
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row)" type="text" size="small">编辑</el-button>
            <el-button type="text" size="small" @click="deleteClick(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-image-viewer
        v-if="showViewer"
        :on-close="() => {showViewer = false;}"
        :url-list="imgList"/>
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.currentPage"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="page.sizeNum"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount">
      </el-pagination>
      <!-- 分页 -->
    </div>
  </div>
</template>

<script>
const datalist = [
  { label: "姓名", prop: "userInfo.userName", align: "center", sort: "custom" },
  {
    label: "学号",
    prop: "userInfo.studentNumber",
    align: "center",
    sort: "custom",
  },
  { label: "年级", prop: "userInfo.grade", align: "center", sort: "custom" },
  { label: "班级", prop: "userInfo.class", align: "center", sort: "custom" },
  { label: "学年", prop: "schoolYear", align: "center", sort: "custom" },
  { label: "学期", prop: "semester", align: "center", sort: "custom" },
  { label: "综测记录", prop: "recordName", align: "center", sort: "custom" },
  { label: "综测类型", prop: "recordType", align: "center", sort: "custom" },
];
export default {
  components: {
    "el-image-viewer": () =>
      import("element-ui/packages/image/src/image-viewer"),
  },
  data() {
    return {
      datalist,
      showViewer: false,
      tableData: [],
      totalCount: null,
      orderField: "", //排序字段
      order: "", //排序方式 descending or ascending
      page: {
        currentPage: 1, // 当前页
        sizeNum: 5, // 每页条数
      },
      imgList: [],
      userId: [],
      studentInfo: [],
    };
  },
  methods: {
    sort(column) {
      // console.log(column);
      // console.log(this.myFunc.formatName(column.prop));
      // this.orderField = this.api.formatName(column.prop);
      if (column.order == "ascending") {
        this.order = "asc";
      } else if (column.order == "descending") {
        this.order = "desc";
      }
      this.getAxios();
    },
    getAxios() {
      this.$axios
        .get("/record/list", {
          params: {
            page: this.page.currentPage,
            limit: this.page.sizeNum,
            orderField: this.orderField,
            order: this.order,
          },
        })
        .then((res) => {
          const data = res.data.data.page;
          // console.log(data.list);
          data.list.forEach((item, index) => {
            if (item.isProved == 0) {
              item.isProved = "待审核";
            } else if (item.isProved == -1) {
              item.isProved = "审核未通过";
            } else if (item.isProved == 1) {
              item.isProved = "审核通过";
            } else {
              item.isProved = "审核中";
            }
          });
          this.tableData = data.list;
          // console.log(this.tableData);
          this.totalCount = data.totalCount;
        });
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.page.sizeNum = val;
      this.getAxios();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.page.currentPage = val;
      this.getAxios();
    },
    look(row) {
      // console.log(row);
      this.imgList.length = 0;
      this.imgList.push(row.proveData);
      this.showViewer = true;
      // console.log(this.imgList);
    },
  },
  created() {
    this.getAxios();
  },
};
</script>

<style lang="scss" scoped>
//深度选择器，去除默认的padding
.el-table {
  /deep/ th {
    height: 20px;
    padding: 0;
  }
  /deep/ td {
    height: 3rem;
    padding: 0;
  }
}
</style>